<?php
class AskController extends commonController{
	public function index(){
		if(IS_POST){
				//判断提交内容
			$this->postcheck();
			$postTime = time();
			$reward= is_null($_POST['reward'])? 0: $_POST['reward'];//悬赏金币
			$uid = $_SESSION['uid']; //用户id
			$cid = $_POST['cid']; //栏目id	
			$content =strip_tags($_POST['content']);
			$content = str_replace(array('\'','\"',',',';'),'',$content); 
			//问答信息写入数据库	
			M('hd_ask')->exec("INSERT INTO hd_ask (content,time,reward,uid,cid) values('$content','$postTime','$reward','$uid','$cid')");
//			$con = M('hd_ask')->query("SELECT * FROM hd_ask wher content='{$content}'");
//			var_dump($con);die;
			//用户信息读取写入   提问数ask+1 point 
			$ask = M('hd_ask')->query("SELECT * FROM hd_user WHERE uid='{$uid}'");
			$ask = $ask[0]['ask']+1;
			$username = $_SESSION['username'];
			M('hd_user')->exec("UPDATE hd_user SET ask='{$ask}' WHERE username='{$username}'");
			$this->success('发布成功',__APP__);
		}
		$this->topCate();
		$this->display();
	}
	/*
	 *异步获取栏目  发布提问
	 */
	public function getSon(){
		$pid = (int)$_POST['pid'];
		$son = M('hd_category')->query("SELECT * FROM hd_category where pid={$pid}");
		echo json_encode($son);
	}

}
